package com.ziJing.multithreading.proxy.test.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DebugInvocationHandler implements InvocationHandler {

    private final Object target;

    public DebugInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //这里就有点像bean的前置方法和后置方法了
        System.out.println("before method " + method.getName());

        Object result = method.invoke(target, args);

        //调用方法之后，我们可以添加自己的额外操作
        System.out.println("after method " + method.getName());


        return result;
    }
}
